/*
	universal.h
	
	Definition of global constants and type definitions
*/

#ifndef ISAMIPS_QEMU_UNIVERSAL
#define ISAMIPS_QEMU_UNIVERSAL

typedef unsigned char reg8b;
typedef unsigned short int reg16b;
typedef unsigned int reg32b;

typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef unsigned short int uint16;
typedef unsigned char uint8;

typedef signed long long sint64;
typedef signed int sint32;
typedef signed short int sint16;
typedef signed char sint8;

typedef uint8 byte;
typedef uint16 halfword;
typedef uint32 word;
typedef uint64 doubleword;

typedef unsigned char bool;

#define NULL 0
#define FALSE 0
#define TRUE 1

#define callback

#define private static
#define public

#define ALIGN4B __attribute__((aligned(4)))

#define GETVARADICPARAMVAL(base, offset, type) (*((type*)(((uint32*)(&base)) + 1 + offset)))
#define GETVARADICPARAMPTR(base, offset, type) ((type*)(*(((uint32*)(&base)) + 1 + offset)))

enum _SyscallCommand{
	SYSCMDSYSMALLOC,
	SYSCMDSYSFREE,
	SYSCMDEXECFROMMEM,
	SYSCMDKILLPROCESS,
	SYSCMDUNDEF
};

typedef enum _SyscallCommand SyscallCommand;

struct _SyscallDescriptor{

	SyscallCommand cmd;
	
	/*payload*/
	union {
	
		/*payload type used for SYSCMDSYSMALLOC*/
		uint32 sysmallocSize;
		
		/*payload type used for SYSCMDSYSFREE*/
		void* sysfreePtr;
		
		/*payload type used for SYSCMDEXECFROMMEM*/
		struct {
			uint8 priority;
			uint8 parentProcID;
			byte* src;
			uint32 size;
		} execFromMem;
		
		/*payload type used for SYSKILLPROCESS*/
		struct{
			void* pd;
		} killProcess;
	} payload;
};

typedef struct _SyscallDescriptor SyscallDescriptor;

struct _SyscallReturnDescriptor{

	bool ifSuccess;

	/*payload*/
	union {
		
		/*payload type used for SYSCMDSYSMALLOC*/
		void* sysmallocRetPtr;
		
		/*payload type used for SYSCMDSYSFREE*/
		sint32 sysfreeRetVal;
		
		/*payload type used for SYSCMDEXECFROMMEM*/
		struct {
			void* pdPtr;
			uint8 processID;
		}execFromMem;
		
		/*payload type used for SYSKILLPROCESS*/
		sint8 killProcessRetVal;
	} payload;
};

typedef struct _SyscallReturnDescriptor SyscallReturnDescriptor;

#endif

